package team.seekers.skill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import team.seekers.skill.entity.dao.QuestionPicture;
import team.seekers.skill.mapper.QuestionPictureMapper;
import team.seekers.skill.service.QuestionPictureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 专为问题设计的地址存放表 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2021-03-05
 */
@Service
public class QuestionPictureServiceImpl extends ServiceImpl<QuestionPictureMapper, QuestionPicture> implements QuestionPictureService {

    @Override
    public List<String> ListByQuestionId(String questionId) {
        QueryWrapper<QuestionPicture> wrapper = new QueryWrapper<>();
        wrapper.eq("question_id",questionId);
        List<QuestionPicture> list = list(wrapper);
        if(list == null){
            return null;
        }
        List<String> pictureList = new ArrayList<>();
        for (QuestionPicture questionPicture : list) {
            pictureList.add(questionPicture.getUrl());
        }
        return pictureList;
    }

    @Override
    public boolean deleteByQuestionId(String questionId){
        QueryWrapper<QuestionPicture> wrapper = new QueryWrapper<>();
        wrapper.eq("question_id",questionId);
        boolean remove = remove(wrapper);
        if(!remove){
            return false;
        }
        return true;
    }
}
